﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(BoxCollider2D))]
public class BaseBrick : MonoBehaviour {

    #region 基本的数据

    [Tooltip("替换后的图片")]
	public Sprite ChangeSprite;

	[Tooltip("砖块产生的物体")]
	public GameObject CreatObject;

	[Tooltip("最多能撞的次数"), SerializeField]
	protected int MaxTimes;
    /// <summary>
    /// 记录目前撞击的次数
    /// </summary>
	protected int nowTimes=0;

    #endregion

    void OnTriggerEnter2D(Collider2D other)
	{
        ///当头顶到砖块且砖块还没有被顶破时
        ///如果有可以生成的物体则生成它
        ///播放上升的动画
		if(other.tag=="Head"&&nowTimes!=MaxTimes)
		{
			nowTimes++;
			if(CreatObject!=null)
				Instantiate(CreatObject,transform.position,Quaternion.identity);
			if(nowTimes==MaxTimes)
				gameObject.GetComponent<SpriteRenderer>().sprite=ChangeSprite;
			GetComponent<Animator>().SetTrigger("Up");
		}
	}
	
}
